package com.vca.admin.controller;

import com.vca.common.page.CommonPage;
import com.vca.common.request.*;
import com.vca.common.response.AdminHeaderResponse;
import com.vca.common.response.TalkSchedulingAdminResponse;
import com.vca.common.result.CommonResult;
import com.vca.common.response.TalkSchedulingAdminByIdResponse;
import com.vca.common.vo.ExcelExSchedulingById;
import com.vca.common.vo.ExcelTalkSchedulingById;
import com.vca.service.service.TalkSchedulingService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 讲座排课控制器
 *
 * @author Li
 * @date 2022/11/15   15:42
 */
@Slf4j
@RestController("TalkSchedulingController")
@RequestMapping("api/admin/talk/scheduling")
@Api(tags = "讲座排课控制器")
public class TalkSchedulingController {

    @Autowired
    private TalkSchedulingService talkSchedulingService;

    /**
     * 讲座排课列表
     * @author Li
     * @date 2022/11/15 15:43
     * @return
     */
    @PreAuthorize("hasAuthority('admin:talk:scheduling:list')")
    @ApiOperation(value = "讲座排课列表")
    @GetMapping("/list")
    public CommonResult<CommonPage<TalkSchedulingAdminResponse>> getList(@ModelAttribute @Validated SchedulingAdminListRequest request, @ModelAttribute PageParamRequest pageParamRequest) {
        CommonPage commonPage = CommonPage.restPage(talkSchedulingService.getAdminList(request,pageParamRequest));
        return CommonResult.success(commonPage);
    }

    @PreAuthorize("hasAuthority('admin:talk:scheduling:getBookingDetail')")
    @ApiOperation(value = "查看预约明细")
    @GetMapping("/getBookingDetail")
    @ApiImplicitParams(
            @ApiImplicitParam(value = "排期id", name = "id")
    )
    public CommonResult<ExcelTalkSchedulingById> getBookingDetail(String id, PageParamRequest pageParamRequest) {
        return CommonResult.success(talkSchedulingService.getBookingDetail(id,pageParamRequest));
    }

    /**
     * 讲座排期日历列表
     * @author Li
     * @date 2022/11/18 16:32
     * @return
     */
    @PreAuthorize("hasAuthority('admin:talk:scheduling:calendar')")
    @ApiOperation(value = "讲座排期日历列表")
    @GetMapping("/calendarList")
    public CommonResult getCalendarList(@ModelAttribute @Validated SchedulingAdminListRequest request){
        return CommonResult.success(talkSchedulingService.getCalendarList(request));
    }

    /**
     * 添加讲座排期
     * @author Li
     * @date  2022/11/18   17:27
     * @return
     */
    @PreAuthorize("hasAuthority('admin:talk:scheduling:add')")
    @ApiOperation(value = "添加讲座排期")
    @PostMapping("/addScheduling")
    public CommonResult addScheduling(@RequestBody SchedulingAddRequest<TalkSchedulingAddRequest> request){
        return talkSchedulingService.addScheduling(request)?CommonResult.success():CommonResult.failed();
    }

    /**
     * 修改讲座排期
     * @author Li
     * @date  2022/11/18   17:27
     * @return
     */
    @PreAuthorize("hasAuthority('admin:talk:scheduling:update')")
    @ApiOperation(value = "修改讲座排期")
    @PostMapping("/updateScheduling")
    public CommonResult updateScheduling(@RequestBody TalkSchedulingAddRequest request){
        return talkSchedulingService.updateScheduling(request)?CommonResult.success():CommonResult.failed();
    }

    /**
     * 排期id查询排期
     * @param talkId
     * @author Li
     * @date 2022/11/21 09:47
     * @return
     */
    @PreAuthorize("hasAuthority('admin:talk:scheduling:get')")
    @ApiOperation(value = "排期id查询排期")
    @GetMapping("/getScheduling")
    public CommonResult<TalkSchedulingAdminByIdResponse> getAdminScheduling(Long talkId){
        return CommonResult.success(talkSchedulingService.getAdminScheduling(talkId));
    }

    /**
     * 根据讲座排期id删除排期
     * @param schedulingId
     * @author Li
     * @date 2022/11/21 14:55
     * @return
     */
    @PreAuthorize("hasAuthority('admin:talk:scheduling:delete')")
    @ApiOperation(value = "根据讲座排期id删除排期")
    @GetMapping("/deleteScheduling")
    public CommonResult deleteScheduling(Long schedulingId){
        return talkSchedulingService.deleteScheduling(schedulingId)?CommonResult.success():CommonResult.failed();
    }


    /**
     * 跟据讲座id查询排期列表
     *
     * @param talkId
     * @param pageParamRequest
     * @return
     * @author Li
     * @date 2022/11/21 09:47
     */
    @ApiOperation(value = "跟据讲座id查询排期列表")
    @GetMapping("/getListByTalk")
    public CommonResult<CommonPage<TalkSchedulingAdminByIdResponse>> getListByCourse(Long talkId, @ModelAttribute PageParamRequest pageParamRequest){
        CommonPage commonPage = CommonPage.restPage(talkSchedulingService.getListByTalk(talkId,pageParamRequest));
        return CommonResult.success(commonPage);
    }

    /**
     * @author Li
     * @date  2022/11/24
     * @return
     */
    @ApiOperation(value = "获得讲座排期头部数据")
    @GetMapping("/header")
    public CommonResult<List<AdminHeaderResponse>> getHeader(String dateLimit,String talkType) {
        return CommonResult.success(talkSchedulingService.getHeader(dateLimit,talkType));
    }

    /**
     * 上架讲座排期预约状态
     * @param talkSchedulingId 讲座排期id
     * @author Li
     * @date    2022/11/18 15:16
     * @return
     */
    @PreAuthorize("hasAuthority('admin:talk:scheduling:shell:on')")
    @ApiOperation("上架讲座排期预约状态")
    @GetMapping("/onShell")
    public CommonResult courseOnShell(Long talkSchedulingId){
        return talkSchedulingService.onShell(talkSchedulingId)?CommonResult.success():CommonResult.failed();
    }

    /**
     * 下架讲座排期预约状态
     * @param talkSchedulingId 讲座排期id
     * @author Li
     * @date    2022/11/18 15:16
     * @return
     */
    @PreAuthorize("hasAuthority('admin:talk:scheduling:shell:off')")
    @ApiOperation("下架讲座排期预约状态")
    @GetMapping("/offShell")
    public CommonResult courseOffShell(Long talkSchedulingId){
        return talkSchedulingService.offShell(talkSchedulingId)?CommonResult.success():CommonResult.failed();
    }

    /**
     * @description 线上讲座绑定微吼直播
     * @param request
     * @author Li
     * @date 2022/12/27 14:52
     * @return com.vca.common.result.CommonResult
     */
    @PreAuthorize("hasAuthority('admin:talk:scheduling:binding')")
    @ApiOperation("线上讲座绑定微吼")
    @PostMapping("/binding")
    public CommonResult TalkBindingVhall(@RequestBody TalkBindingVhallRequest request){
        return talkSchedulingService.TalkBindingVhall(request)?CommonResult.success():CommonResult.failed();
    }

    /**
     * @description 取消讲座排期
     * @methodName cancel
     * @param request
     * @author Li
     * @date 2022/12/28 16:14
     * @return com.vca.common.result.CommonResult
     */
    @PreAuthorize("hasAuthority('admin:talk:scheduling:cancel')")
    @ApiOperation("取消讲座排期")
    @PostMapping("/cancel")
    public CommonResult cancel(@RequestBody SchedulingCancelRequest request){
        return talkSchedulingService.cancel(request)?CommonResult.success():CommonResult.failed();
    }
}
